package com.vito.dcs.water.trace.action;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.exception.ParamErrorException;
import com.vito.base.model.ResMsg;
import com.vito.base.model.Result;
import com.vito.base.util.Validata;
import com.vito.dcs.water.trace.model.TraceWaterModel;
import com.vito.dcs.water.trace.service.TraceWaterService;

/**
 * 水稳传输数据汇总表请求控制器
 * @author  lyhao E-mail: 
 * @version 0.0.1
 * @date    2019-4-23 16:07:24
 */
@Controller
@RequestMapping("/dcs/water/trace")
public class TraceWaterAction extends BaseAction {
	
	private static final Logger log = LoggerFactory.getLogger(TraceWaterAction.class);
	
	@Reference
	private TraceWaterService tracewaterServiceImpl;
	
	/**
	 * 保存水稳传输数据汇总表
	 * @author  lyhao E-mail: 
	 * @version 创建时间：2019-4-23 16:07:24
	 * @return  code:状态码 ,msg:提示信息
	 * @param   tracewater 需要保存的水稳传输数据汇总表对象
	 *		 	<li>Id:主键 不能为null 或空字符串</li>
	 *		 	<li>SectionId:标段id 不能为null 或空字符串</li>
	 *		 	<li>TransDate:传输日期 不能为null 或空字符串</li>
	 *		 	<li>StartMileage:起始里程 不能为null 或空字符串</li>
	 *		 	<li>EndMileage:结束里程 不能为null 或空字符串</li>
	 *		 	<li>LayerId:摊铺层级 不能为null 或空字符串</li>
	 *		 	<li>PavingArea:摊铺面积 不能为null 或空字符串</li>
	 *		 	<li>TotalDischarge:出料总数 不能为null 或空字符串</li>
	 */
	@RequestMapping("saveTraceWater")
	@ResponseBody
	public Result saveTraceWater(@RequestBody TraceWaterModel tracewater){
		Result res = new Result();
		try{
			Validata.isNullOrEmpty(tracewater, "水稳传输数据汇总表不能为空");
			Validata.isNullOrEmpty(tracewater.getId(), "主键不能为空");
			Validata.isNullOrEmpty(tracewater.getSectionId(), "标段id不能为空");
			Validata.isNullOrEmpty(tracewater.getTransDate(), "传输日期不能为空");
			Validata.isNullOrEmpty(tracewater.getStartMileage(), "起始里程不能为空");
			Validata.isNullOrEmpty(tracewater.getEndMileage(), "结束里程不能为空");
			Validata.isNullOrEmpty(tracewater.getLayerId(), "摊铺层级不能为空");
			Validata.isNullOrEmpty(tracewater.getPavingArea(), "摊铺面积不能为空");
			Validata.isNullOrEmpty(tracewater.getTotalDischarge(), "出料总数不能为空");
			tracewaterServiceImpl.saveTraceWater(tracewater);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.SAVESUC);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("保存失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 分页查询水稳传输数据汇总表
	 * @author  lyhao E-mail: 
	 * @version 创建时间：2019-4-23 16:07:24
	 * @return  {code:0,data:{total:20,rows:[{}...]}}
	 * @param   tracewater 依靠水稳传输数据汇总表对象分页查询
	 *          <li>pageNo default 1</li>
	 *          <li>pageSize default 15</li>
	 */
	@RequestMapping("queryTraceWaterByPage")
	@ResponseBody
	public Result queryTraceWaterByPage(TraceWaterModel tracewater){
		Result res = new Result();
		try{
			Validata.isNullOrEmpty(tracewater, "水稳传输数据汇总表不能为空");
			res.setData(tracewaterServiceImpl.queryTraceWaterByPage(tracewater));
			res.setCode(Result.CODE_OK);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 查询一条水稳传输数据汇总表
	 * @author  lyhao E-mail: 
	 * @version 创建时间：2019-4-23 16:07:24
	 * @return  {code:0,data:{...}}
	 * @param   tracewater 依靠水稳传输数据汇总表对象查询
	 */
	@RequestMapping("queryTraceWater")
	@ResponseBody
	public Result queryTraceWater(TraceWaterModel tracewater){
		Result res = new Result();
		try{
			res.setData(tracewaterServiceImpl.queryTraceWater(tracewater));
			res.setCode(Result.CODE_OK);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
		
	/**
	 * 更新水稳传输数据汇总表对象
	 * @author  lyhao E-mail: 
	 * @version 创建时间：2019-4-23 16:07:24
	 * @return  {code:0,data:10}
	 * @param   tracewater 依靠水稳传输数据汇总表对象的id变更传入的其他属性值
	 *		 	<li>Id:主键 不能为null 或空字符串</li>
	 *		 	<li>SectionId:标段id 不能为null 或空字符串</li>
	 *		 	<li>TransDate:传输日期 不能为null 或空字符串</li>
	 *		 	<li>StartMileage:起始里程 不能为null 或空字符串</li>
	 *		 	<li>EndMileage:结束里程 不能为null 或空字符串</li>
	 *		 	<li>LayerId:摊铺层级 不能为null 或空字符串</li>
	 *		 	<li>PavingArea:摊铺面积 不能为null 或空字符串</li>
	 *		 	<li>TotalDischarge:出料总数 不能为null 或空字符串</li>
	 */
	@RequestMapping("updateTraceWater")
	@ResponseBody
	public Result updateTraceWater(TraceWaterModel tracewater){
		Result res = new Result();
		try{
			tracewaterServiceImpl.updateTraceWater(tracewater);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.UPDSUC);
		}catch(Exception ex){
			log.error("更新失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 删除水稳传输数据汇总表对象
	 * @author  lyhao E-mail: 
	 * @version 创建时间：2019-4-23 16:07:24
	 * @return  {code:0,data:10}
	 * @param   tracewater 删除水稳传输数据汇总表对象的 checkeds 标识的id对应的数据
	 */
	@RequestMapping("deleteTraceWater")
	@ResponseBody
	public Result deleteTraceWater(TraceWaterModel tracewater){
		Result res = new Result();
		try{
			Validata.isNullOrEmpty(tracewater.getCheckeds(), "所选项不能为空");
			
			res.setData(tracewaterServiceImpl.deleteTraceWater(tracewater));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.DELCOM);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("删除失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	@RequestMapping("findQualityInfo")
	@ResponseBody
	public Result findQualityInfo(@RequestParam String id){
		Result rs = new Result();
		try{
			rs = tracewaterServiceImpl.findQualityInfo(id);
		}catch(Exception ex){
			log.error("查询失败",ex);
			rs.setCode(Result.CODE_ERROR);
			rs.setMsg(ResMsg.EXECERR);
		}
		return rs;
	}
}



